package com.future.direction.ui.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.future.direction.R;
import com.future.direction.common.util.UIUtil;
import com.future.direction.interfaces.OnItemClickListener;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by zhp on 2019/10/25
 */
public class TeamAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private int mPosition = 0;
    private OnItemClickListener onItemClickListener;
    private OnItemClickListener onPhoneClickListener;
    private OnItemClickListener onInfoClickListener;

    public void setPosition(int position) {
        this.mPosition = position;
    }

    public void setOnPhoneClickListener(OnItemClickListener onPhoneClickListener) {
        this.onPhoneClickListener = onPhoneClickListener;
    }

    public void setOnInfoClickListener(OnItemClickListener onInfoClickListener) {
        this.onInfoClickListener = onInfoClickListener;
    }

    public int getmPosition() {
        return mPosition;
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        return new TeamViewHolder(LayoutInflater.from(UIUtil.getContext()).inflate(
                R.layout.item_team, parent, false));

    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {

        if (holder instanceof TeamViewHolder) {
            TeamViewHolder teamViewHolder = (TeamViewHolder) holder;

            teamViewHolder.ivItemTeamName.setText("大哥");
            teamViewHolder.tvItemTeamBuyCount.setText("7");
            teamViewHolder.tvItemTeamInviteCount.setText("7人");
            teamViewHolder.ivItemTeamPhone.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (null != onPhoneClickListener) {
                        onPhoneClickListener.onItemClick(v, position);
                    }
                }
            });
            teamViewHolder.ivItemTeamInfo.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (null != onInfoClickListener) {
                        onInfoClickListener.onItemClick(v, position);
                    }
                }
            });
            teamViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (null != onItemClickListener) {
                        onItemClickListener.onItemClick(v, position);
                    }
                }
            });
        }
    }

    @Override
    public int getItemCount() {
        return 6;
    }

    public static class TeamViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.iv_item_team)
        ImageView ivItemTeam;
        @BindView(R.id.iv_item_team_name)
        TextView ivItemTeamName;
        @BindView(R.id.tv_item_team_buy_count)
        TextView tvItemTeamBuyCount;
        @BindView(R.id.tv_item_team_invite_count)
        TextView tvItemTeamInviteCount;
        @BindView(R.id.iv_item_team_phone)
        ImageView ivItemTeamPhone;
        @BindView(R.id.iv_item_team_info)
        ImageView ivItemTeamInfo;

        public TeamViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

}
